package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_QiYe_DetailsActivity;
import com.example.xianji.R;
import com.example.xianji.bean.FuWu;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EnterpriseAdapter extends BaseAdapter {
    private ArrayList<FuWu> list;
    private Context mContext;


    public EnterpriseAdapter(ArrayList<FuWu> list, Context mContext) {
        super();
        this.list = list;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return arg0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;

        if (convertView == null) {
            mHolder = new Holder();
            convertView = View.inflate(mContext, R.layout.qiye_liebiao_listview_item, null);
            mHolder.gongsi_liebiao_name = (TextView) convertView.findViewById(R.id.gongsi_liebiao_name);
            mHolder.qiye_fenlei_tag = (TextView) convertView.findViewById(R.id.qiye_fenlei_tag);
            mHolder.qiye_liebiao_place = (TextView) convertView.findViewById(R.id.qiye_liebiao_place);
            convertView.setTag(mHolder);
        }
        mHolder = (Holder) convertView.getTag();

        mHolder.gongsi_liebiao_name.setText(list.get(position).getTitle());
        mHolder.qiye_fenlei_tag.setText(list.get(position).getCat_name());
        mHolder.qiye_liebiao_place.setText(list.get(position).getProvince_name() + "  " + list.get(position).getCity_name());

        final int a = position;

        convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, Main_QiYe_DetailsActivity.class);
                intent.putExtra("gongsi_id", list.get(a).getId());
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }

    class Holder {
        TextView gongsi_liebiao_name;
        TextView qiye_fenlei_tag;
        TextView qiye_liebiao_place;
    }
}
